# Author ： chosen-yn
from Config import *
import logging
import time
from conf import LOGGING_DIC
import logging.config


def get_logger(file_path, name=''):
    LOGGING_DIC['handlers']['default']['filename'] = file_path

    logging.config.dictConfig(LOGGING_DIC)
    logger = logging.getLogger(name)
    return logger


# 获取登录账户信息
def get_stock_account():
    acc = StockAccount('10100001021')
    subscribe_result = xt_trader.subscribe(acc)
    return subscribe_result


# 校验股票号
def validate_stock_code(stock_number):
    if '.' not in stock_number:
        return False, f"代码 {stock_number} 格式错误!没有尾缀！"
    parts = stock_number.split('.')
    if len(parts) != 2:
        return False, f"代码 {stock_number} 格式错误!"
    number_part, letter_part = parts
    if not number_part.isdigit() or len(number_part) != 6:
        return False, f"代码 {stock_number} 不是数字并且字符长度不足六位！"
    if not letter_part.isalpha() or len(letter_part) != 2:
        return False, f"代码 {stock_number} 不是字母并且字符长度不足两位!"
    return True, ''


# 校验订单编号
def validate_order_number(order_number):
    if len(str(order_number)) != 10:
        return False, f"订单编号 {order_number} 字符长度不足十位！"
    return True, ''


def create_log(log, acc):
    time_now = time.strftime("%Y-%m-%d %H:%M:%S")
    log = f"当前用户{acc}于{time_now}执行{log} "
    return log
